package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author LiShunSen
 * @Date 2024-08-28
 */
@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    NursingLevelMapper nursingLevelMapper;


    public List<NursingLevelVo> getAll() {
        List<NursingLevelVo> nursingLevelVo = nursingLevelMapper.getAll();

        return nursingLevelVo;
    }

    /**
     * 新增
     *
     * @param nursingLevelDto
     * @return
     */
    public void insertLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insertLevel(nursingLevel);
    }

    /**
     * 分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageResponse<NursingLevelVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        Page<NursingLevel> page = nursingLevelMapper.getByPage(name, status,pageNum,pageSize);

        return PageResponse.of(page,NursingLevelVo.class);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    public NursingLevelVo getId(Long id) {

        return nursingLevelMapper.getId(id);
    }

    /**
     * 修改
     *
     * @param nursingLevelDto
     * @return
     */
    public void updateLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);

        nursingLevelMapper.updateLevel(nursingLevel);
    }

    @Override
    public void deleteLevel(Long id) {

        nursingLevelMapper.deleteLevel(id);
    }

    /*
     * 启用/禁用护理计划
     * @param id
     * @param status
     * @return
     */
    public void statusLevel(Long id, Integer status) {
        nursingLevelMapper.statusLevel(id,status);
    }
}
